<!-- 会签管理》添加待会签单位 -->
<template>
	<view>
		<van-cell value="单位" />
		<van-grid :column-num="3" :border="false" :center="false" >
			<van-checkbox-group v-model="result" direction="horizontal" @change="groupChange">
				<van-grid-item v-for="(item,index) in orgList" :key="item.id" >
					<van-checkbox  :name="item.value" :v-model="item.value" icon-size="16"  shape="round" >{{item.name}}</van-checkbox>
				</van-grid-item>
			</van-checkbox-group>
		</van-grid>
		<view class="btn-container">
			<view class="bottom-btn">
				<van-button class="left-btn" color="#0066FF" plain  type="info" size="small" @click="goBack">取消</van-button>
				<van-button class="right-btn" color="#0066FF"   type="info" size="small" @click="submitOrg">确定</van-button>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				fwId:'',//发文id
				proInstId:'',
				result:[],
				orgList: [
				  // {id:'001002',name:"综合司"},
				  // {id:'001003',name:"综合司"},
				  // {id:'001004',name:"政法司"},
				  // {id:'001005',name:"计划司"},
				  // {id:'001007',name:"国际司"}
				  ]
			}
		  },
		  onLoad:function(option) {
		  	//从地址栏获取proInstId
		  	this.fwId= option.fwId
			this.proInstId= option.proInstId
		  	// console.log(proInstId);

		  },
		  mounted() {
		  	this.getCountersignMhj()
		  },
		  methods: {
			  //获取会签单位选择列表
			  getCountersignMhj(){
			  	var _this = this
			  	this.$httploading({
			  	  url: this.$httploading.adornUrl(`/caac/oa/doc/fdj/getCountersignMhj`),
			  	  method: 'get',
			  	  params: this.$httploading.adornParams({
			  		 'systemKey': this.cache.get('userInfo').systemKey,//固定值
			  		 'systemFlag': this.cache.get('userInfo').systemFlag,//固定值
			  	  })
			  	}).then(({data}) => {
			  		//{"name":"办公室","id":"002001005","sort":3,"value":"002001005_办公室_3961"}
			  		if(data.code==200){
						_this.orgList = data.data
			  		}else{
			  			console.log(data);
			  		}

			  	})
			  },

			  //添加待发送会签单位
			  updateCountersigning(countersignValue){
			  	var _this = this
			  	this.$httploading({
			  	  url: this.$httploading.adornUrl(`/caac/oa/mhjcomponent/countersign/countersignController/updateCountersigning`),
			  	  method: 'POST',
			  	  params: this.$httploading.adornParams({
			  		  'systemKey': this.cache.get('userInfo').systemKey,//固定值
			  		  'systemFlag': this.cache.get('userInfo').systemFlag,//固定值
					  'fwId': this.fwId,
					  'countersignValue':countersignValue
			  	  })
			  	}).then(({data}) => {
			  		console.log("添加待发送会签单位: " + JSON.stringify(data));
			  		if(data.code==200){
						//添加成功关闭当前页面，返回上一界面
						this.$toast('添加成功')
						// this.$refs.conSign.listHuiqianInfo(this.fwId)//调用con-sign页面的获取待发送会签单位方法更新列表
						uni.navigateBack({
							animationType: 'pop-out',
							animationDuration: 2000
						})
			  		}else{
			  			console.log(data);
			  		}

			  	})
			  },

			  groupChange(event){
				  // console.log(event)
			  },
			  goBack(){
				  uni.navigateBack({
					  animationType: 'pop-out',
					  animationDuration: 2000
				  })
			  },
			  submitOrg(){
				  if(this.result.length>0){
					// alert('提交选中单位：'+this.result.toString())
					this.updateCountersigning(this.result.toString())

				  }else{
					  this.$toast('未选中任何单位')
				  }
			  }
		  },
	  }
</script>

<style>
	.cu-form-group{
		border: 2rpx solid #e4e4e4;
		border-radius: 10rpx;
	}
	.textarea{
		margin: 32rpx 0 30rpx;
		height: 300rpx;
		width: 100%;
		line-height: 40rpx;
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		font-size: 32rpx;
		padding: 0;


	}
	.sub-btn{
		display: flex;
		flex-direction: row;
		justify-content: center;
		width: 100%;
	}
	.sub-btn .van-button{
		margin-top: 120rpx;
		height: 88rpx;
		width: 260rpx;
		border-radius: 14rpx;
	}
	.btn-container{
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
		width: 100%%;
		padding: 0 80rpx;
		justify-content: center;
	}
	.bottom-btn{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin: 50rpx 0 100rpx;
	}
	.bottom-btn .left-btn{
		border-radius: 10rpx;
		width: 45%;
	}
	.bottom-btn .right-btn{
		border-radius: 10rpx;
		width: 45%;
	}
</style>
